<template>
    <view class="page-background">
        <view class="feeback-type">
            <view class="title font-30">{{ $t('feedbackPage.problemType') }}</view>
            <view class="type-box">
                <view v-for="(item, index) in type" @tap="to_active(item)" :key="index" :class="['type-item font-28', item.active ? 'active' : '', $i18n.locale]">
                    {{ item.label }}
                </view>
            </view>
        </view>
        <view class="idea-input">
            <view class="font-30">{{ $t('feedbackPage.problemDescription') }}</view>
            <textarea type="text" v-model="content" :maxlength="500" :placeholder="$t('feedbackPage.textareaPlaceholder')" />
            <view class="font-26 color-999 other">{{ $t('feedbackPage.textareaTips') }}</view>
        </view>
        <view class="register-check font-30" :class="[$i18n.locale]" @tap="submit">{{ $t('submitTips') }}</view>
    </view>
</template>

<script>
export default {
    data() {
        return {
            content: '',
            few: false,
            type: []
        }
    },
    onLoad() {
        uni.setNavigationBarTitle({
            title: this.$i18n.t('feedbackPage.navigationBarTitle')
        })
    },
    mounted() {
        this.$http('get|api/User/user_consult').then(res => {
            this.type = res.result.consult_type.map((row, index) => {
                return {
                    label: row,
                    active: false,
                    value: index
                }
            })
            this.type[0].active = true
        })
    },
    methods: {
        submit() {
            let content = this.content.trim()
            if (!content) {
                this.$toastApp(this.$t('feedbackPage.textareaCheckoutEmptyTips'))
                return
            }
            this.$http('post|api/User/user_consult', {
                content: content,
                consult_type: this.type.find(row => row.active).value
            })
                .then(res => {
                    this.$toastApp(res.msg)
                    setTimeout(() => {
                        uni.navigateBack()
                    }, 500)
                })
                .catch(err => {
                    this.$toastApp(err.msg)
                })
        },
        to_active(item) {
            this.type.forEach(el => {
                el.active = false
            })
            item.active = true
        }
    }
}
</script>

<style lang="scss">
.register-check {
    width: 658rpx;
    height: 90rpx;
    border-radius: 45rpx;
    line-height: 90rpx;
    text-align: center;
    margin: 0 auto;
    margin-top: 110rpx;
    color: #ffffff;
    &.zh {
        background: var(--theme);
    }
    &.hk {
        background: var(--themeHK);
    }
}
.color-999 {
    color: #999999;
}
.idea-input {
    padding: 30rpx;
    box-sizing: border-box;
    background-color: #ffffff;
}
.idea-input textarea {
    height: 320rpx;
    background-color: #f3f3f3;
    margin-top: 20rpx;
    font-size: 26rpx;
    line-height: 30rpx;
    box-sizing: border-box;
    width: 100%;
    padding: 20rpx;
}
.other {
    line-height: 40rpx;
    margin-top: 10rpx;
}
.register-check {
    margin-left: auto;
    margin-right: auto;
}
.feeback-type {
    padding: 36rpx 0 0 46rpx;
    box-sizing: border-box;
    .type-box::after {
        clear: both;
        content: '';
        display: block;
    }
    .type-item {
        float: left;
        width: 176rpx;
        height: 68rpx;
        border-radius: 12rpx;
        border: 1px solid #d4d4d4;
        text-align: center;
        line-height: 68rpx;
        margin-top: 30rpx;
        color: #a4a4a4;
        margin-right: 50rpx;
    }
    .active {
        &.zh {
            color: var(--theme);
            border-color: var(--theme);
        }
        &.hk {
            color: var(--themeHK);
            border-color: var(--themeHK);
        }
    }
}
</style>
